#!/usr/bin/env python

import pymongo
client = pymongo.MongoClient("mongodb://localhost:27017")
db = client.anstack

file_name = 'nginx.var.yml'

service_name =  file_name.split('.')[0]

f = open(file_name, 'r')

db.service.insert_one({"_id": service_name})

for line in f.readlines():
    if line.strip():
        print line
        key = line.split(":")[0]
        service_parameters = line.split(":")[1].strip()
    else:
        continue
    key = "parameters." + key
    result = db.service.update_one({"_id": service_name},{"$set": {key: service_parameters}})
    print "result: " + str(result.matched_count)
